{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9c586a68",
   "metadata": {},
   "source": [
    "### 第几天"
   ]
  },
  {
   "cell_type": "raw",
   "id": "037135ec",
   "metadata": {},
   "source": [
    "2000年的1月1日，是那一年的第1天。\n",
    "那么，2000年的5月4日，是那一年的第几天？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "329f34c5",
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime, timedelta\n",
    "start = datetime.strptime('2000/01/01', '%Y/%m/%d')\n",
    "\n",
    "end = datetime.strptime('2000/05/04', '%Y/%m/%d')\n",
    "\n",
    "num = 1\n",
    "\n",
    "while True:\n",
    "    start = start + timedelta(1)\n",
    "    num += 1\n",
    "    if start == end:\n",
    "        break\n",
    "\n",
    "print(num)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "02e337c3",
   "metadata": {},
   "source": [
    "### 明码"
   ]
  },
  {
   "cell_type": "raw",
   "id": "ce8c5bb4",
   "metadata": {},
   "source": [
    "汉字的字形存在于字库中，即便在今天，16点阵的字库也仍然使用广泛。\n",
    "16点阵的字库把每个汉字看成是16x16个像素信息。并把这些信息记录在字节中。\n",
    "\n",
    "一个字节可以存储8位信息，用32个字节就可以存一个汉字的字形了。\n",
    "把每个字节转为2进制表示，1表示墨迹，0表示底色。每行2个字节，\n",
    "一共16行，布局是：\n",
    "\n",
    "    第1字节，第2字节\n",
    "    第3字节，第4字节\n",
    "    ....\n",
    "    第31字节, 第32字节\n",
    "\n",
    "这道题目是给你一段多个汉字组成的信息，每个汉字用32个字节表示，这里给出了字节作为有符号整数的值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f7101e50",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "with open('word.txt', 'r') as f:\n",
    "    content = f.read()\n",
    "    \n",
    "content = content.split('\\n')\n",
    "\n",
    "content = [row.split(' ') for row in content]\n",
    "  \n",
    "content = [row[:32] for row in content]\n",
    "\n",
    "content = [[format(int(char), '0b').zfill(8) for char in row] for row in content]\n",
    "\n",
    "num = 0\n",
    "for row in content:\n",
    "    \n",
    "    for char in row:\n",
    "        print(char, end='')\n",
    "        num += 1\n",
    "    \n",
    "        if num == 2:\n",
    "            num = 0 \n",
    "            print(\"\\n\")\n",
    "        \n",
    "    print(\"\\n\")\n",
    "    print(\"\\n\")\n",
    "\n",
    "\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c5d52a26",
   "metadata": {},
   "source": [
    "### 乘积尾零"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "219b927f",
   "metadata": {},
   "outputs": [],
   "source": [
    "如下的10行数据，每行有10个整数，请你求出它们的乘积的末尾有多少个零？\n",
    "\n",
    "5650 4542 3554 473 946 4114 3871 9073 90 4329 \n",
    "2758 7949 6113 5659 5245 7432 3051 4434 6704 3594 \n",
    "9937 1173 6866 3397 4759 7557 3070 2287 1453 9899 \n",
    "1486 5722 3135 1170 4014 5510 5120 729 2880 9019 \n",
    "2049 698 4582 4346 4427 646 9742 7340 1230 7683 \n",
    "5693 7015 6887 7381 4172 4341 2909 2027 7355 5649 \n",
    "6701 6645 1671 5978 2704 9926 295 3125 3878 6785 \n",
    "2066 4247 4800 1578 6652 4616 1113 6205 3264 2915 \n",
    "3966 5291 2904 1285 2193 1428 2265 8730 9436 7074 \n",
    "689 5510 8243 6114 337 4096 8199 7313 3685 211 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "36e7bc50",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('product.txt' , 'r') as f:\n",
    "    content = f.read()\n",
    "    \n",
    "content = content.split('\\n')\n",
    "\n",
    "content = [row.split(' ') for row in content]\n",
    "\n",
    "content = [row[:10] for row in content]\n",
    "\n",
    "tmp = list()\n",
    "\n",
    "for row in content:\n",
    "    for char in row:\n",
    "        tmp.append(int(char))\n",
    "\n",
    "\n",
    "result = 0\n",
    "p = 1\n",
    "for i in tmp:\n",
    "    p *= i\n",
    "    string = str(p)\n",
    "    tmp_string = string\n",
    "    for char in tmp_string[::-1]:\n",
    "        if char == '0':\n",
    "            result += 1\n",
    "            string = string[:-1]\n",
    "        else:\n",
    "            break\n",
    "    \n",
    "    p = int(string)\n",
    "    \n",
    "print(result)\n",
    "\n",
    "\n",
    "\"\"\"\n",
    "result = 1\n",
    "for num in tmp:\n",
    "    result *= num\n",
    "    \n",
    "print(result)\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "82795cb9",
   "metadata": {},
   "source": [
    "### 测试次数"
   ]
  },
  {
   "cell_type": "raw",
   "id": "08bd4b57",
   "metadata": {},
   "source": [
    "x星球的居民脾气不太好，但好在他们生气的时候唯一的异常举动是：摔手机。\n",
    "各大厂商也就纷纷推出各种耐摔型手机。x星球的质监局规定了手机必须经过耐摔测试，\n",
    "并且评定出一个耐摔指数来，之后才允许上市流通。\n",
    "\n",
    "x星球有很多高耸入云的高塔，刚好可以用来做耐摔测试。\n",
    "塔的每一层高度都是一样的，与地球上稍有不同的是，\n",
    "他们的第一层不是地面，而是相当于我们的2楼。\n",
    "\n",
    "如果手机从第7层扔下去没摔坏，但第8层摔坏了，则手机耐摔指数=7。\n",
    "特别地，如果手机从第1层扔下去就坏了，则耐摔指数=0。\n",
    "如果到了塔的最高层第n层扔没摔坏，则耐摔指数=n\n",
    "\n",
    "为了减少测试次数，从每个厂家抽样3部手机参加测试。\n",
    "\n",
    "某次测试的塔高为1000层，如果我们总是采用最佳策略，\n",
    "在最坏的运气下最多需要测试多少次才能确定手机的耐摔指数呢？\n",
    "\n",
    "请填写这个最多测试次数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "499d8fc8",
   "metadata": {},
   "outputs": [],
   "source": [
    "from math import log2\n",
    "\n",
    "print(log2(1000+1))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f4da118",
   "metadata": {},
   "source": [
    "### 快速排序"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d260b033",
   "metadata": {},
   "source": [
    "### 递增三元组 "
   ]
  },
  {
   "cell_type": "raw",
   "id": "fff97ff5",
   "metadata": {},
   "source": [
    "给定三个整数数组\n",
    "A = [A1, A2, ... AN], \n",
    "B = [B1, B2, ... BN], \n",
    "C = [C1, C2, ... CN]，\n",
    "请你统计有多少个三元组(i, j, k) 满足：\n",
    "1. 1 <= i, j, k <= N  \n",
    "2. Ai < Bj < Ck  \n",
    "\n",
    "【输入格式】 \n",
    "第一行包含一个整数N。\n",
    "第二行包含N个整数A1, A2, ... AN。\n",
    "第三行包含N个整数B1, B2, ... BN。\n",
    "第四行包含N个整数C1, C2, ... CN。\n",
    "\n",
    "对于30%的数据，1 <= N <= 100  \n",
    "对于60%的数据，1 <= N <= 1000 \n",
    "对于100%的数据，1 <= N <= 100000 0 <= Ai, Bi, Ci <= 100000 \n",
    "\n",
    "【输出格式】\n",
    "一个整数表示答案\n",
    "\n",
    "【样例输入】\n",
    "3\n",
    "1 1 1\n",
    "2 2 2\n",
    "3 3 3\n",
    "\n",
    "【样例输出】\n",
    "27 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f7c4ee29",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "N = int(input())\n",
    "\n",
    "nums = [list(map(int, input().split())) for _ in range(N)]\n",
    "\n",
    "from itertools import product\n",
    "\n",
    "production = list(product(*nums))\n",
    "\n",
    "num = 0\n",
    "for _list in  production:\n",
    "    i = _list[0]\n",
    "    j = _list[1]\n",
    "    k = _list[2]\n",
    "    \n",
    "    if 1 <= i <= N and 1 <= j <= N and 1 <= k <= N and i <= j <= k:\n",
    "        num += 1\n",
    "        \n",
    "print(num)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a0b73b6",
   "metadata": {},
   "source": [
    "### 螺旋折线"
   ]
  },
  {
   "cell_type": "raw",
   "id": "820050b2",
   "metadata": {},
   "source": [
    "如图p1.png所示的螺旋折线经过平面上所有整点恰好一次。  \n",
    "对于整点(X, Y)，我们定义它到原点的距离dis(X, Y)是从原点到(X, Y)的螺旋折线段的长度。  \n",
    "\n",
    "例如dis(0, 1)=3, dis(-2, -1)=9  \n",
    "\n",
    "给出整点坐标(X, Y)，你能计算出dis(X, Y)吗？\n",
    "\n",
    "【输入格式】\n",
    "X和Y  \n",
    "\n",
    "对于40%的数据，-1000 <= X, Y <= 1000  \n",
    "对于70%的数据，-100000 <= X， Y <= 100000  \n",
    "对于100%的数据, -1000000000 <= X, Y <= 1000000000  \n",
    "\n",
    "【输出格式】\n",
    "输出dis(X, Y)  \n",
    "\n",
    "\n",
    "【样例输入】\n",
    "0 1\n",
    "\n",
    "【样例输出】\n",
    "3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "290a422d",
   "metadata": {},
   "outputs": [],
   "source": [
    "X, Y = map(int, input().split())\n",
    "\n",
    "_X, _Y = 0 , 0\n",
    "\n",
    "flag = 'left'\n",
    "count = 1\n",
    "while True:\n",
    "    if flag == 'left':\n",
    "        _X -= count\n",
    "        if _X == 0:\n",
    "            \n",
    "            "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a53d6913",
   "metadata": {},
   "source": [
    "### 全球变暖"
   ]
  },
  {
   "cell_type": "raw",
   "id": "0147468f",
   "metadata": {},
   "source": [
    "你有一张某海域NxN像素的照片，\".\"表示海洋、\"#\"表示陆地，如下所示：\n",
    "\n",
    ".......\n",
    ".##....\n",
    ".##....\n",
    "....##.\n",
    "..####.\n",
    "...###.\n",
    ".......\n",
    "\n",
    "其中\"上下左右\"四个方向上连在一起的一片陆地组成一座岛屿。例如上图就有2座岛屿。  \n",
    "\n",
    "由于全球变暖导致了海面上升，科学家预测未来几十年，岛屿边缘一个像素的范围会被海水淹没。具体来说如果一块陆地像素与海洋相邻(上下左右四个相邻像素中有海洋)，它就会被淹没。  \n",
    "\n",
    "例如上图中的海域未来会变成如下样子：\n",
    "\n",
    ".......\n",
    ".......\n",
    ".......\n",
    ".......\n",
    "....#..\n",
    ".......\n",
    ".......\n",
    "\n",
    "请你计算：依照科学家的预测，照片中有多少岛屿会被完全淹没。  \n",
    "\n",
    "【输入格式】\n",
    "第一行包含一个整数N。  (1 <= N <= 1000)  \n",
    "以下N行N列代表一张海域照片。  \n",
    "\n",
    "照片保证第1行、第1列、第N行、第N列的像素都是海洋。  \n",
    "\n",
    "【输出格式】\n",
    "一个整数表示答案。\n",
    "\n",
    "【输入样例】\n",
    "7 \n",
    ".......\n",
    ".##....\n",
    ".##....\n",
    "....##.\n",
    "..####.\n",
    "...###.\n",
    ".......  \n",
    "\n",
    "【输出样例】\n",
    "1  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ab68140",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "N = int(input())\n",
    "\n",
    "photo = [list(input()) for _ in range(N)]\n",
    "\n",
    "tmp = photo.copy()\n",
    "for i in range(1, N-1):\n",
    "    for j in range(1, N-1):\n",
    "        print(tmp[i][j])\n",
    "        if tmp[i-1][j] == '#' and tmp[i+1][j] == '#' and tmp[i][j-1] == '#' and tmp[i][j+1] == '#':\n",
    "            pass\n",
    "        else:\n",
    "            photo[i][j] = '.'\n",
    "\n",
    "photo = [\"\".join(line) for line in photo]\n",
    "print(\"\\n\\n\")\n",
    "print(*photo,sep='\\n')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "222c311f",
   "metadata": {},
   "source": [
    "### 乘积最大"
   ]
  },
  {
   "cell_type": "raw",
   "id": "5b598916",
   "metadata": {},
   "source": [
    "给定N个整数A1, A2, ... AN。请你从中选出K个数，使其乘积最大。  \n",
    "\n",
    "请你求出最大的乘积，由于乘积可能超出整型范围，你只需输出乘积除以1000000009的余数。\n",
    "\n",
    "输入样例】\n",
    "5 3 \n",
    "-100000   \n",
    "-10000   \n",
    "2   \n",
    "100000  \n",
    "10000  \n",
    "\n",
    "【输出样例】\n",
    "999100009"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "909fd1ca",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "N, K = map(int, input().split())\n",
    "\n",
    "nums = [int(input()) for _ in range(N)]\n",
    "\n",
    "chose = list()\n",
    "for _ in range(K):\n",
    "    max_num = max(nums)\n",
    "    chose.append(max_num)\n",
    "    nums.remove(max_num)\n",
    "\n",
    "    \n",
    "from math import  prod\n",
    "print(prod(chose) % 1000000009)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "lanqiaobei",
   "language": "python",
   "name": "lanqiaobei"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
